﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace GISDeveloping_test4
{

    public class MapDocument
    {
        IMapDocument m_MapDocument;

        /// <summary>
        /// 打开地图文档
        /// </summary>
        /// <param name="axMapControl1"></param>
        /// <param name="sFilePath"></param>
        public void OpenDocument(AxMapControl axMapControl1, string sFilePath)
        {
            if (m_MapDocument != null)
            {
                m_MapDocument.Close();
            }
            m_MapDocument = new MapDocumentClass();
            m_MapDocument.Open(sFilePath, "");
            axMapControl1.Map = m_MapDocument.ActiveView as IMap;
        }



        /// <summary>
        /// 保存地图文档
        /// </summary>
        /// <param name="axMapControl1"></param>
        public void SaveDocument(AxMapControl axMapControl1)
        {
            if (m_MapDocument != null)
            {
                m_MapDocument.Close();
            }
            IMxdContents pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "地图文档(*.mxd)|*.mxd";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                m_MapDocument.New(saveFile.FileName);
                m_MapDocument.ReplaceContents(pMxdC);
                m_MapDocument.Save(true, true);
                MessageBox.Show("地图文档保存成功");

            }


        }
    }
}
